Skip to content

fix: persist delivered email body in MemberEmailDelivery - #2827

Merged
mroderick merged 4 commits into
masterfrom
fix/email-delivery-logs-empty-body
Aug 31, 2026
Merged

fix: persist delivered email body in MemberEmailDelivery#2827
mroderick merged 4 commits into
masterfrom
fix/email-delivery-logs-empty-body

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Problem

member_email_deliveries.body has never captured any content — all 439 rows in production are empty, so the email audit log cannot show what was actually sent.

Root cause

premailer-rails registers a Mail interceptor that runs during delivery: it converts the message to multipart/alternative (adding a plain-text part and inlining CSS), which empties the body container. EmailDelivery#log_sent_email then runs in an after_deliver callback and reads mail.body.to_s — the now-empty container — storing "".

The emails themselves are unaffected: recipients receive complete multipart/alternative messages with both plain-text and HTML parts. Only the audit log is broken. Chaser dedup checks row existence, not body, so it works as before.

Fix

Read the html part instead of the body container:

body: mail.html_part ? mail.html_part.body.to_s : mail.body.to_s,

Pure plain-text mailers (no html part) fall back to mail.body as before.

Testing

Extended the MemberMailer#chaser logging spec to assert the persisted row has a body containing the template copy. Confirmed red→green: the assertion fails with "" on master and passes with the fix. Full mailer specs and the three-month chaser service spec pass (85 examples), RuboCop clean.

Context

Found while diagnosing chaser reliability for #2384 (chaser introduced in #2449 for #2383).

premailer-rails converts messages to multipart/alternative during
delivery, emptying the body container. The EmailDelivery concern read
`mail.body.to_s` in an after_deliver callback, so every logged row had
an empty body (439 of 439 rows in production). Read the html part
instead so the audit log captures the delivered content.
@mroderick
mroderick requested a review from olleolleolle August 31, 2026 08:29
@mroderick
mroderick marked this pull request as ready for review August 31, 2026 08:29
Comment thread app/mailers/concerns/email_delivery.rb Outdated
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
@mroderick
mroderick enabled auto-merge August 31, 2026 08:47
@mroderick
mroderick merged commit 80412ad into master Aug 31, 2026
9 checks passed
@mroderick
mroderick deleted the fix/email-delivery-logs-empty-body branch August 31, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants